package no.gnet.edvd.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;

public class Utilities {
	
	public static String hashAndHexEncodePw(String pw) throws UnsupportedEncodingException,
			NoSuchAlgorithmException {
		byte[] bytes = pw.getBytes("UTF-8");
		MessageDigest md = MessageDigest.getInstance("SHA-256");
		byte[] hash = md.digest(bytes);
		char[] chars = Hex.encodeHex(hash);
		return new String(chars);
	}
}
